var filter = angular.module('starter.filter', []);
var storage = window.localStorage;
filter.filter('dateFormat',function(){
    return function(item){
        //alert(item)
        return new Date(item).toLocaleString();
    }
});

filter.filter('deltaDate',function(){
    return function(item){
        if(item == 'undefined' || !item){
            return ' -- ';
        }
        if((''+item).length > 10){
            return parseInt(((new Date().getTime() - new Date(item).getTime())/1000/60));
        }else{
            return parseInt(((new Date().getTime()/1000 - new Date(item).getTime())/60));
        }
    }
});

var orderStaeArray = {
    1000:'已创建，未付款',
    2000:'已付款，未审核',
    2500:'已审核，未出单',
    3000:'已出单，未打包',
    4000:'已打包，未中转',
    4500:'已中转，未抵达',
    5000:'已抵达，未分配',
    6000:'已分配，未领件',
    6900:'预约派送',
    7000:'已领件，未派送',
    8000:'已派送，未签收',
    9000:'已签收，未评价',
    9001:'退货待受理',
    9002:'退货受理中',
    9003:'退货已受理',
    9004:'客户拒收',
    9999:'已评价',
    '-1':'用户取消',
    '-2':'平台取消'
};
filter.filter('orderState',function(){
    return function(code){
        if(code<0){
            code = code+'';
        }
        return orderStaeArray[code];
    }
});
var orderTpe = {
    9:'商家外卖',
    11:'退货',
    12:'换货'
};
filter.filter('orderTpe',function(){
    return function(code){
        if(code<0){
            code = code+'';
        }
        return orderTpe[code];
    }
});
var orderTypeCode = {
    0:"普",
    1:'团',
    2:'秒',
    3:'普',
    4:'活动',
    5:'预',
    6:'外',
    7:'包月',
    8:'营销',
    9:'三方',
    11:'退货',
    12:'换货'
};
filter.filter('orderTypeName',function(){
    return function(code){
        return orderTypeCode[code];
    }
});

filter.filter('number',function(){
    return function(code){
        if(code){
            return code;
        }else{
            return 0;
        }

    }
});
filter.filter('colorString',function($sce){
    return function(code){
        if(code){
            var colorString = code.slice(-6);
            var first = code.substr(0,code.length-6) ;
            var html = "<span>"+first+"</span><span style='font-size: large;color: red;'>"+colorString+"</span>" ;
            return $sce.trustAsHtml(html);
        }else{
            return 0;
        }
    }
});
var payway = {
    "WXPAY":"微信支付",
    "ALIPAY":"支付宝支付",
    "MEITUANPAY":"美团支付",
    "BAIDUPAY":"百度支付",
    "YUEPAY":"余额支付",
    "DAOPAY":"到付"
}
filter.filter('payway',function($sce){
    return function(code){
        if(code){
            return payway[code];
        }else{
            return payway[2];
        }

    }
});


